package com.example.demo.demo;


import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.util.*;

/**
 * @Description
 * @Author
 * @Date 2019/10/12 11:30
 **/
public class Demo {
    public static void main(String[] args) {

        String image = "";
        final String s = image.substring(image.lastIndexOf(".") + 1).toLowerCase();


        isValid("()[]");
       String[] aa =new String[]{"flower","flow","flight"};
        longestCommonPrefix(aa);
        boolean matches = "6912398000003180".matches("^[A-Z0-9]+$");
        int reverse1 = reverse(-123);


        int x1 =10;
        int reverse = Integer.reverse(x1);
        long l = System.currentTimeMillis();
        long fullCount = 0, fullTime = 0, youngCount = 0, youngTime = 0;
        ArrayList<HashMap> hashMaps = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            HashMap<Object, Object> map = new HashMap<>();
            map.put(i,i);
            hashMaps.add(map);
        }
        hashMaps.forEach(x->x.put(1,2));
        List<GarbageCollectorMXBean> gcs = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean gc : gcs) {
            System.out.println(gc.getName());
            System.out.println(gc.getCollectionCount());
            System.out.println(gc.getCollectionTime());
            System.out.println("--------------------");
        }
    }

    public static boolean isValid(String s) {
        if(s==null||s.length()==0){
            return false;
        }
        if(s.length()%2==1){
            return false;
        }
        int i=1;
        char[] bys = new char[s.length()];
        bys[0] = s.charAt(0);
        for (int i1 = 1; i1 < s.length(); i1++) {
            if(i>0&&getValue(bys[i-1])+getValue(s.charAt(i1))==0){
                //弹栈
                i -=1;
            }else {
                //压栈
                bys[i]=s.charAt(i1);
                i +=1;
            }
        }
        return i==0;
    }

    public static int getValue(Character ch){
        switch (ch){
            case '(':
                return 1;
            case ')':
                return -1;
            case '[':
                return 2;
            case ']':
                return -2;
            case '{':
                return 3;
            case '}':
                return -3;
            default:
                return 0;
        }
    }

    public static int reverse(int x) {
        int a;
        int b=0;
        int max = x>0?Integer.MAX_VALUE:Integer.MIN_VALUE;
        while (x!=0){
            a=x%10;
            x=x/10;
            if(b!=0&&max/b<10) return 0;
            if(max-b*10<a) return 0;
            b = b*10+a;
        }
        return b;
    }
    public static String replaceSymbol(String source,String ignore){
        String regex="[^A-Za-z0-9"+ignore+"]";
        return source.replaceAll(regex,"");
    }

    public static String longestCommonPrefix(String[] strs) {
        StringBuilder sb = new StringBuilder();
        int length=Integer.MAX_VALUE;
        for (String str : strs) {
            length = Math.min(length,str.length());
        }
        if(length==0){
            return "";
        }
        char a;
        for (int i = 0; i < length; i++) {
            a = strs[0].charAt(i);
            for (int i1 = 1; i1 < strs.length; i1++) {
                if(a!=strs[i1].charAt(i)){
                    return sb.toString();
                }
            }
            sb.append(a);
        }
        return sb.toString();
    }


    public static int hailstone(int n){
        int length = 0;
        while (n>1){
            if(n%2==1){
                n= n/2;
            }else {
                n = 3*n +1;
            }
            length++;
        }
        return length;
    }

}
